<style>
	.layui-table-cell {
		padding:0 5px;
		height:auto;
		overflow:visible;
		text-overflow:inherit;
		white-space:normal;
		word-break: break-all;
	}
	.layui-table-cell{padding:1px 3px;line-height:20px;}
	.laytable-cell-1-0-0{text-align:center;}
	.layui-form-pane .layui-form-label{width:auto;}
	.layui-form-item{margin-bottom: 0px;}
	.order-time-bg{background-color:#1E9FFF;color:white;padding:0px 5px;}
	.material-status span,.material-status a{font-weight:bold;font-size:14px;}
	.fixed-bar-tr-header{
		z-index:2;
		margin-top: 25px;
		/*margin-top: 65px;*/
	}
</style>
<div class="fixed-bar">
	<form class="layui-form layui-form-pane fixed-bar-form" action="{:url()}" method="get" id="hisi-table-search-optable" >
		{if ($action!='searchLabel')}
		<div class="layui-form-item source_form">
			<div class="layui-inline">
				<label class="layui-form-label">订单号</label>
				<div class="layui-input-inline">
					<input type="text" name="client_ordernum" lay-verify="" placeholder="输入订单号" class="layui-input">
				</div>
			</div>
			{if env('env_site') == 'riwei' }
			<div class="layui-inline">
				<label class="layui-form-label">客户单号</label>
				<div class="layui-input-inline">
					<input type="text" name="ext_id" lay-verify="" placeholder="输入客户单号" class="layui-input">
				</div>
			</div>
			{/if}
			<div class="layui-inline removeStat">
				<label class="layui-form-label">SKU</label>
				<div class="layui-input-inline">
					<input type="text" name="sku" lay-verify="" placeholder="输入SKU" class="layui-input">
				</div>
			</div>
			<div class="layui-inline removeStat">
				<label class="layui-form-label">所属工厂</label>
				<div class="layui-input-inline">
					{:Form::select('factory_id', '', $factoryKV, '', '')}
				</div>
			</div>
			<div class="layui-inline removeStat">
				<label class="layui-form-label">物料状态</label>
				<div class="layui-input-inline">
					{:Form::select('material_status', '', [0 => '请选择', 1=>'未采购', 2=>'采购中',  3=>'换料中',4=>'已到料',5=>'未批色',6=>'批色不通过',7=>'已批色',13=>'未发货',14=>'已发货',8=>'批色已齐套',9=>'批色未齐套',10=>'采购未齐套',11=>'采购已齐套',15=>'发货未齐套',16=>'发货已齐套',12=>'可裁剪'], 'material_status_select', '',' lay-filter="material_status_select" ')}
				</div>
			</div>
			<div class="layui-inline removeStat">
				<label class="layui-form-label">物料类型</label>
				<div class="layui-input-inline">
					<input type="hidden" name="material_property_v2" value="0">
					{:Form::select('material_property', '', [0 => '全部', 1=>'面料', 2=>'铺料'], 'material_property_select', '',' lay-filter="material_property_select" disabled ')}
				</div>
			</div>
			<div class="layui-inline removeStat">
				<label class="layui-form-label">到料状态</label>
				<div class="layui-input-inline">
					<input type="hidden" name="arrive_time_status_v2" value="0">
					{:Form::select('arrive_time_status', '', [0 => '全部', 1=>'已按过到料', 2=>'没按过到料'], 'arrive_time_status_select', '',' lay-filter="arrive_time_status_select" disabled  ')}
				</div>
			</div>
			<div class="layui-inline removeStat">
				<label class="layui-form-label">下单日期</label>
				<div class="layui-input-inline">
					<input type="text" name="create_date_range" readonly="" id="create_date_range" lay-verify="" placeholder="选择下单日期" class="layui-input">
				</div>
			</div>
			<div class="layui-inline removeStat">
				<label class="layui-form-label">账号</label>
				<div class="layui-input-inline">
					{:Form::select('is_auto_import', '', $orderFrom, '', '')}
				</div>
			</div>
			<div class="layui-inline removeStat">
				<label class="layui-form-label">单类</label>
				<div class="layui-input-inline">
					{:Form::select('type', '', [''=>'全部','normal'=>'返单','new'=>'首单','emergent'=>'紧急单','my_first'=>'奖励(第一次做不含尾货)','my_return_first'=>'初返(不含尾货)'], '', '')}
				</div>
			</div>
			<div class="layui-inline removeStat">
				<label class="layui-form-label">超期筛选</label>
				<div class="layui-input-inline">
					{:Form::select('out_time_limit', '', [0=>'请选择',3=>'超3天',5=>'超5天',8=>'超8天以上'], '', '')}
				</div>
			</div>
			<div class=" layui-inline layui-upload">
				<button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1" >搜索</button>
				<button type="button"   class="layui-btn layui-btn-primary export_btn">导出</button>
			</div>
		</div>
		{else /}
		<div class="layui-form-item search_label_form">
			<div class="layui-inline">
				<label class="layui-form-label">订单号</label>
				<div class="layui-input-inline">
					<input type="text" name="client_ordernum" lay-verify="" placeholder="输入订单号" class="layui-input">
				</div>
			</div>
			<div class=" layui-inline layui-upload">
				<button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1" >搜索</button>
				<button type="button"   class="layui-btn layui-btn-primary export_btn">导出</button>
				<input type="hidden" name="a" value="searchLabel">
				<input type="hidden" name="labelid" value="{$labelid}">
			</div>
			<div class=" layui-inline">
				标签内容：{:$labelinfo['material_status']}  {:$labelinfo['factory_ids_str']} 显示物料：{:$labelinfo['material_type']} 时间：{:$labelinfo['time']}
			</div>
		</div>
		{/if}
	</form>
</div>
<!-- 进度统计 -->
<div class="layui-collapse removeStat" lay-accordion>
	<div class="layui-colla-item">
		<h2 class="layui-colla-title">数据统计</h2>
		<div class="layui-colla-content layui-show1">
			<table class="layui-table">
				<thead>
				<tr>
					<th>不含尾货</th>
					<th>下单数</th>
					<th>面料采购已完成单数</th>
					<th>换料中单数</th>
					<th>面料采购未完成单数</th>
					<th>已批色单数</th>
					<th>未批色单数</th>
					<th>批色不通过单数</th>
					<th>已验布缩水单数</th>
					<th>未验布缩水单数</th>
					<th>已裁单数</th>
					<th>未裁单数</th>
					<th>辅料发放单数</th>
					<th>辅料未发放单数</th>
					<th>辅料采购未完成</th>
				</tr>
				</thead>
				<tbody>
				<tr>
					<td>单数</td>
					<td><a href="{:url()}?a=stat&sc=allCount" class="ac-item hisi-iframe" title="下单数" hisi-data="{width: '80%', height: '80%'}">0</a></td>
					<td><a href="{:url()}?a=stat&sc=fabricCgOverCount" class="stat-fcoc-item hisi-iframe" title="面料采购已完成单数" hisi-data="{width: '80%', height: '80%'}">0</a></td>
					<td><a href="{:url()}?a=stat&sc=returnMaterialCount" class="stat-rmc-item hisi-iframe" title="退料中单数" hisi-data="{width: '80%', height: '80%'}">0</a></td>
					<td><a href="{:url()}?a=stat&sc=fabricCgNotCount" class="stat-fcnc-item hisi-iframe" title="面料采购未完成单数" hisi-data="{width: '80%', height: '80%'}">0</a></td>
					<td><a href="{:url()}?a=stat&sc=apColorOverCount" class="stat-acoc-item hisi-iframe" title="已批色通过单数" hisi-data="{width: '80%', height: '80%'}">0</a></td>
					<td><a href="{:url()}?a=stat&sc=apColorNotCount" class="stat-acnc-item hisi-iframe" title="未批色单数" hisi-data="{width: '80%', height: '80%'}">0</a></td>
					<td><a href="{:url()}?a=stat&sc=apColorNoCount" class="stat-acnoc-item hisi-iframe" title="批色不通过单数" hisi-data="{width: '80%', height: '80%'}">0</a></td>
					<td><a href="{:url()}?a=stat&sc=ckClothSkOverCount" class="stat-csoc-item hisi-iframe" title="已验布缩水单数" hisi-data="{width: '80%', height: '80%'}">0</a></td>
					<td><a href="{:url()}?a=stat&sc=ckClothSkNotCount" class="stat-csnc-item hisi-iframe" title="未验布缩水单数" hisi-data="{width: '80%', height: '80%'}">0</a></td>
					<td><a href="{:url()}?a=stat&sc=caichuangOverCount" class="stat-coc-item hisi-iframe" title="已裁单数" hisi-data="{width: '80%', height: '80%'}">0</a></td>
					<td><a href="{:url()}?a=stat&sc=caichuangNotCount" class="stat-cnc-item hisi-iframe" title="未裁单数" hisi-data="{width: '80%', height: '80%'}">0</a></td>
					<td><a href="{:url()}?a=stat&sc=acOverCount" class="stat-aoc-item hisi-iframe" title="辅料发放单数" hisi-data="{width: '80%', height: '80%'}">0</a></td>
					<td><a href="{:url()}?a=stat&sc=acNotCount" class="stat-anc-item hisi-iframe" title="待领料单数" hisi-data="{width: '80%', height: '80%'}">0</a></td>
					<td><a href="{:url()}?a=stat&sc=acNoCount" class="stat-acNoCount-item hisi-iframe" title="辅料采购未完成" hisi-data="{width: '80%', height: '80%'}">0</a></td>
				</tr>
				<tr>
					<td>完成率</td>
					<td class=""></td>
					<td class="stat-fcocp-item">0%</td>
					<td class="stat-rmcp-item">0%</td>
					<td class="stat-fncp-item">0%</td>
					<td class="stat-acocp-item">0%</td>
					<td class="stat-acncp-item">0%</td>
					<td class="stat-acnocp-item">0%</td>
					<td class="stat-csocp-item">0%</td>
					<td class="stat-csncp-item">0%</td>
					<td class="stat-cocp-item">0%</td>
					<td class="stat-cncp-item">0%</td>
					<td class="stat-aocp-item">0%</td>
					<td class="stat-ancp-item">0%</td>
					<td class="stat-acNoCountp-item">0%</td>
				</tr>
				</tbody>
			</table>
		</div>
	</div>
</div>
<!-- 时效统计 -->
<div class="layui-tab layui-tab-card" style="display: none">
	<ul class="layui-tab-title">
		<li class="layui-this">时效统计</li>
	</ul>
	<div class="layui-tab-content">
		<div class="layui-tab-item layui-show">
			<!-- 订单时效统计 -->
			<div class="layui-collapse removeStat" lay-accordion>
				<div class="layui-colla-item">
					<h2 class="layui-colla-title">订单时效统计</h2>
					<div class="layui-colla-content layui-show1">
						<table class="layui-table">
							<thead>
							<tr>
								<th rowspan="2">不含尾货</th>
								<th colspan="2">采购时效</th>
								<th colspan="2">面料处理时效</th>
								<th colspan="2">裁床时效</th>
								<th colspan="2">缝前时效</th>
							</tr>
							<tr>
								<th>单数</th>
								<th>百分比</th>
								<th>单数</th>
								<th>百分比</th>
								<th>单数</th>
								<th>百分比</th>
								<th>单数</th>
								<th>百分比</th>
							</tr>
							</thead>
							<tbody class="order" id="statistics_order_shixiao">
							<tr>
								<td>一天内完成</td>
								<td>0</td>
								<td>0%</td>
								<td>0</td>
								<td>0%</td>
								<td>0</td>
								<td>0%</td>
								<td>0</td>
								<td>0%</td>
							</tr>
							<tr>
								<td>两天内完成</td>
								<td>0</td>
								<td>0%</td>
								<td>0</td>
								<td>0%</td>
								<td>0</td>
								<td>0%</td>
								<td>0</td>
								<td>0%</td>
							</tr>
							<tr>
								<td>三天内完成</td>
								<td>0</td>
								<td>0%</td>
								<td>0</td>
								<td>0%</td>
								<td>0</td>
								<td>0%</td>
								<td>0</td>
								<td>0%</td>
							</tr>
							<tr>
								<td>四天内完成</td>
								<td>0</td>
								<td>0%</td>
								<td>0</td>
								<td>0%</td>
								<td>0</td>
								<td>0%</td>
								<td>0</td>
								<td>0%</td>
							</tr>
							<tr>
								<td>四天以上完成</td>
								<td>0</td>
								<td>0%</td>
								<td>0</td>
								<td>0%</td>
								<td>0</td>
								<td>0%</td>
								<td>0</td>
								<td>0%</td>
							</tr>
							<tr>
								<td>未完成</td>
								<td>0</td>
								<td>0%</td>
								<td>0</td>
								<td>0%</td>
								<td>0</td>
								<td>0%</td>
								<td>0</td>
								<td>0%</td>
							</tr>
							</tbody>
						</table>
					</div>
				</div>
			</div>
			<!-- 物料时效统计 -->
			<div class="layui-collapse removeStat" lay-accordion>
				<div class="layui-colla-item">
					<h2 class="layui-colla-title">物料时效统计</h2>
					<div class="layui-colla-content layui-show1">
						<table class="layui-table">
							<thead>
							<tr>
								<th rowspan="2">不含尾货</th>
								<th colspan="2">面料打标时效</th>
								<th colspan="2">辅料打标时效</th>
								<th colspan="2">批色时效</th>
								<th colspan="2">验布时效</th>
								<th colspan="2">缩水时效</th>
							</tr>
							<tr>
								<th>数量</th>
								<th>百分比</th>
								<th>数量</th>
								<th>百分比</th>
								<th>数量</th>
								<th>百分比</th>
								<th>数量</th>
								<th>百分比</th>
								<th>数量</th>
								<th>百分比</th>
							</tr>
							</thead>
							<tbody class="order" id="statistics_material_shixiao">
							<tr>
								<td>12小时内完成</td>
								<td>0</td>
								<td>0%</td>
								<td>0</td>
								<td>0%</td>
								<td>0</td>
								<td>0%</td>
								<td>0</td>
								<td>0%</td>
								<td>0</td>
								<td>0%</td>
							</tr>
							<tr>
								<td>24小时内完成</td>
								<td>0</td>
								<td>0%</td>
								<td>0</td>
								<td>0%</td>
								<td>0</td>
								<td>0%</td>
								<td>0</td>
								<td>0%</td>
								<td>0</td>
								<td>0%</td>
							</tr>
							<tr>
								<td>36小时内完成</td>
								<td>0</td>
								<td>0%</td>
								<td>0</td>
								<td>0%</td>
								<td>0</td>
								<td>0%</td>
								<td>0</td>
								<td>0%</td>
								<td>0</td>
								<td>0%</td>
							</tr>
							<tr>
								<td>48小时内完成</td>
								<td>0</td>
								<td>0%</td>
								<td>0</td>
								<td>0%</td>
								<td>0</td>
								<td>0%</td>
								<td>0</td>
								<td>0%</td>
								<td>0</td>
								<td>0%</td>
							</tr>
							<tr>
								<td>48小时以上完成</td>
								<td>0</td>
								<td>0%</td>
								<td>0</td>
								<td>0%</td>
								<td>0</td>
								<td>0%</td>
								<td>0</td>
								<td>0%</td>
								<td>0</td>
								<td>0%</td>
							</tr>
							<tr>
								<td>未完成</td>
								<td>0</td>
								<td>0%</td>
								<td>0</td>
								<td>0%</td>
								<td>0</td>
								<td>0%</td>
								<td>0</td>
								<td>0%</td>
								<td>0</td>
								<td>0%</td>
							</tr>
							</tbody>
						</table>
					</div>
				</div>
			</div>
		</div>
		<div class="layui-tab-item">
			3333
		</div>
	</div>
</div>
{if ($action!='searchLabel')}
<div class="layui-colla-title removeStat" style="height:auto;border-radius:2px;padding:3px 14px;margin-top:10px;"><span class="searchLabeltag">{:$labelstr}</span>
	<a href="{:url('material/searchLabelList')}" class="layui-btn layui-btn-primary layui-btn-sm layui-icon layui-icon-set hisi-iframe"  hisi-data="{width: '85%', height:'95%'}" style="float:right;margin-top:5px;" title="自定义搜索标签">&nbsp;设置</a>
</div>
{/if}
<table id="dataTable" lay-filter='dataTable'></table>

{include file="system@block/layui" /}

<script type="text/html" id="picTpl">
	<span class="lay-pic-container" src="{{ d.pic }}">
		<img src="{{ d.ori_pic }}" class="lay-pic">
		{{# if(d.status==99){ }}
			<span class="sign"><img src="/static/system/image/sign_delete.png"></span>
		{{# }else if(d.status==2){ }}
			<span class="sign"><img src="/static/system/image/sign_over.png"></span>
		{{# }else if(d.tail_status==1){ }}
			<span class="sign"><img src="/static/system/image/sign_tail.png"></span>
		{{# }else if(d.chejian_status==1){ }}
			<span class="sign"><img src="/static/system/image/sign_workshop.png"></span>
		{{# }else if(d.caichuang_status==1){ }}
			<span class="sign"><img src="/static/system/image/sign_cutting.png"></span>
		{{# }else if(d.caigou_status==1){ }}
			<span class="sign"><img src="/static/system/image/sign_purchasing_done.png"></span>
		{{# }else { }}
			<span class="sign"><img src="/static/system/image/sign_purchasing_todo.png"></span>
		{{# } }}
	</span>
</script>
<script type="text/html" id="skuTpl">
	<span class="copy-item">{{ d.client_ordernum }}</span> <span class="layui-badge layui-bg-blue">{{ layui.tool.formatOrderOType(d.o_type) }}</span><span class="layui-badge layui-bg-orange">{{ layui.tool.formatOrderType(d.type) }}</span>
	{{# if(d.type_ext == 'my_return_first'){ }}
	<span class="layui-badge layui-bg-green">初返</span>
	{{# } }}
	<br>
	{if env('env_site') == 'riwei' }
	<span class="copy-item">{{ d.ext_id }}</span> <br>
	{/if}
	<span class="copy-item">{{ d.sku }}</span> <br>
	{{ d.shipment_time_diff }} <br>
	{{ d.create_time_diff }} <br>
	{{# if(d.status == 99){ }}<span class="layui-badge">{{ d.delete_text }}</span> {{# } }}
	{{ orderFrom[d.is_auto_import] }}
</script>
<script type="text/html" id="factoryTpl">
	{{ d.factory_name }} <br>
	{{ d.group_name }} <br>
	{{# if(d.outgo_status > 0){ }}
	外发：{{ d.factory_outgo_name }}
	{{# } }}

</script>
<script type="text/html" id="skuStockTpl">
	{{# if(d.skuStock.length>0){ var all_stock_count=0; }}
	<div style="writing-mode: tb-rl;float:left;width:28px;padding-top:10px;letter-spacing:4px;font-weight:bold;color:red;">可用库存</div>
	<div style="margin-left:30px;">
		{{# for(var i in d.skuStock){ all_stock_count+=parseInt(d.skuStock[i].available_count); }}
		{{ d.skuStock[i].size_name }}： {{ d.skuStock[i].available_count }} <br>
		{{# } }}
		总：{{all_stock_count}}
	</div>
	{{# } }}
</script>
<script type="text/html" id="orderNumTpl">
	{{# for(var i in d.osList){ }}
	{{ d.osList[i].size_name }}： <span title="下单数">{{ d.osList[i].order_count }}</span> / <span title="裁床数">{{ d.osList[i].shicai_count }}</span> / <span title="车间数">{{ d.osList[i].jiaohuo_count }}</span> / <span title="后整数">{{ d.osList[i].jiaohuo_tail_count }}</span> / <span title="打包数">{{ d.osList[i].delivery_count }}</span> / <span title="出货数">{{ d.osList[i].daohuo_count }}</span> <br>
	{{# } }}
	总数：<span title="总下单数">{{ d.osStat.order_count }}</span> / <span title="总裁床数">{{ d.osStat.shicai_count }}</span> / <span title="总车间数">{{ d.osStat.jiaohuo_count }}</span> / <span title="总后整数">{{ d.osStat.jiaohuo_tail_count }}</span> / <span title="总打包数">{{ d.osStat.delivery_count }}</span> / <span title="总出货数">{{ d.osStat.daohuo_count }}</span>
</script>
<script type="text/html" id="orderTimeTpl">
	<div class="{{# if(d.create_time > 0){ }}order-time-bg{{# } }}">下单：{{# if(d.create_time > 0){ }} {{ layui.util.toDateString(d.create_time * 1000) }} {{# } }}</div>
	<div class="{{# if(d.shipment_time > 0){ }}order-time-bg{{# } }}">货期：{{# if(d.shipment_time > 0){ }} {{ layui.util.toDateString(d.shipment_time * 1000) }} {{# } }}</div>
	<div class="{{# if(d.caigou_over_time > 0){ }}order-time-bg{{# } }}">采购：{{# if(d.caigou_over_time > 0){ }} {{ layui.util.toDateString(d.caigou_over_time * 1000) }} {{# } }}</div>
	<div class="{{# if(d.caichuang_over_time > 0){ }}order-time-bg{{# } }}">裁床：{{# if(d.caichuang_over_time > 0){ }} {{ layui.util.toDateString(d.caichuang_over_time * 1000) }} {{# } }}</div>
	<div class="{{# if(d.chejian_over_time > 0){ }}order-time-bg{{# } }}">车间：{{# if(d.chejian_over_time > 0){ }} {{ layui.util.toDateString(d.chejian_over_time * 1000) }} {{# } }}</div>
	<div class="{{# if(d.tail_over_time > 0){ }}order-time-bg{{# } }}">尾部：{{# if(d.tail_over_time > 0){ }} {{ layui.util.toDateString(d.tail_over_time * 1000) }} {{# } }}</div>
	<div class="{{# if(d.over_time > 0){ }}order-time-bg{{# } }}">总完：{{# if(d.over_time > 0){ }} {{ layui.util.toDateString(d.over_time * 1000) }} {{# } }}</div>
</script>
<script type="text/html" id="orderUserTpl">
	{{# if(d.caigou_status==1){ }}
	{{ d.caigou_user_name }}
	{{# }else{ }}
	{{ layui.tool.showSelect('caigou_user_id', d.caigou_user_id, purchasingUserKV, 'caigou-user', d.id) }}
	{{# } }}

</script>
<script type="text/html" id="buttonTpl">
	<div style="line-height:35px;">
		{{# if(d.approval_color_all==0){ }}
		<a href="{:url('approvalColor')}?order_id={{ d.id }}&mid=0" title="全部批色" class="layui-btn layui-btn-sm hisi-ajax layui-btn-warm approval-color-{{ d.id }}" confirm="您确定要执行该操作吗？" refresh="false" callback="callbackApprovalColor">全部批色</a><br>
		{{# } }}
	</div>
	<a href="{:url('updateCaichuangCanDo')}?order_id={{ d.id }}" title="更新裁剪状态" class="layui-btn layui-btn-sm hisi-ajax" refresh="false">更新裁剪状态</a><br>
</script>


<script type="text/html" title="余料使用量" id="subMaterialUseTpl">
	{{# if(d.type=='accessories'){ }}
	{{ d.stock_use_num }}
	{{# }else{ }}
	{{ d.apply_and_used_0_used }} / {{ d.have_metres }}
	{{# if(d.apply_and_used_0_used > 0 || d.have_metres >0){ }}
	<a href="{:url('materialStock/apply')}?material_id={{ d.material_id }}&client_ordernum={{ d.client_ordernum }}" title="余料占用" class="layui-btn layui-btn-normal layui-btn-sm hisi-iframe" hisi-data="{width: '800px', height: '500px'}">占用</a>
	{{# } }}
	{{# } }}
</script>

<script type="text/html" title="还需用量" id="needNumTpl">
	{{# if(d.type=='accessories'){ }}
	{{ layui.tool.bcsub(d.total_material_dosage, d.stock_use_num) }}
	{{# }else{ }}
	{{ layui.tool.bcsub(d.total_material_dosage, (d.apply_and_used_0_apply + d.apply_and_used_0_used)) }}
	{{# } }}
</script>

<script type="text/html" title="打标日志" id="shijiCaigouTpl">
	{{# if(d.shiji_caigou_count!=''){ }}
	<a href="{:url('makeTagLog')}?mid={{ d.mid }}" title="总条数" class="hisi-iframe" hisi-data="{width: '800px', height: '500px'}">{{ d.shiji_caigou_count }}</a>
	{{# } }}
</script>
<script type="text/html" title="来退料明细" id="tiaoshuDetailTpl">
	{{# if(d.tiaoshu_detail!=''){ }}
	<a href="{:url('materialLog')}?mid={{ d.mid }}" title="来退料明细" class="hisi-iframe" hisi-data="{width: '500px', height: '400px'}">{{ d.tiaoshu_detail }}</a>
	{{# } }}
</script>

<script type="text/html" title="物料状态" id="purchasingStatusTpl">
	<div class="material-status material-status-{{ d.mid }}">
		{{# if(d.type!='accessories' && d.material_status.is_make_tag==1 && d.material_status.is_caigou_start==2 && d.material_status.is_checkcloth!=1 && d.material_status.is_shrink!=1 && d.tiaoshu_status!=10 && d.caigou_status==1){ }}
		<span class="green">可裁剪</span>
		{{# }else{ }}

		{{# if(d.material_status.is_caigou_start==0){ }}
		{{# if(d.type=='accessories'){ }}
		<a href="javascript:void(0)" data-material_id="{{ d.material_id }}" data-mid="{{ d.mid }}" data-order_id="{{ d.order_id }}" title="开始采购" class="orange start-purchasing">
			开始采购{{# if(d.arrive_time>0){ }}<span style="color:#996600"> -已到料</span>{{# } }}
		</a>
		{{# }else{ }}
		<a href="javascript:void(0)" data-mid="{{ d.mid }}" data-order_id="{{ d.order_id }}" data-material_id="{{ d.material_id }}" data-order_from="{{ orderFrom[d.p.is_auto_import] }}" data-client_ordernum="{{ d.client_ordernum }}" data-name="{{ d.name }}" data-colornum="{{ d.colornum }}" data-color="{{ d.color }}" data-num="{{ d.total_material_dosage - d.apply_and_used_0_apply - d.apply_and_used_0_used }}" data-model="{{ d.model }}" data-weight="{{d.weight}}" data-sku="{{ d.sku }}" title="开始采购" class="orange start-purchasing-metre">
			开始采购{{# if(d.arrive_time>0){ }}<span style="color:#996600"> -已到料</span>{{# } }}
		</a>
		{{# } }}
		{{# }else if(d.material_status.is_caigou_start==1){ }}
		<span class="red">采购中 {{# if(d.arrive_time>0){ }}<span style="color:#996600"> -已到料</span>{{# } }}</span>
		{{# }else if(d.tiaoshu_status!=10){ }}
		<span class="green">采购完成 </span>
		{{# }else { }}
		<span class="green">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
		{{# } }}

		{{# if(d.tiaoshu_status==10){ }}
		<span class="red">换料中</span>
		{{# }else if(d.tiaoshu_status==11){ }}
		<span class="green">换料完成</span>
		{{# } }}

		{{# if(d.type!='accessories'){ }}
		<br>
		{{# if(d.material_status.is_checkcloth==0){ }}
		<span class="green">无需验布</span>
		{{# }else if(d.material_status.is_checkcloth==1 && d.tiaoshu>0 ){ }}
		<span class="red">验布中</span>
		{{# }else if(d.material_status.is_checkcloth==2 && d.tiaoshu>0 ){ }}
		<span class="green">验布完成</span>
		{{# }else{ }}
		<span class="green">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
		{{# } }}


		{{# if(d.material_status.is_shrink==0 || d.factory_id==14){ }}
		<span class="green">无需缩水</span>
		{{# }else if(d.material_status.is_shrink==1 && d.tiaoshu>0){ }}
		<span class="red">缩水中</span>
		{{# }else if(d.material_status.is_shrink==2 && d.tiaoshu>0 ){ }}
		<span class="green">缩水完成</span>
		{{# }else{ }}
		<span class="green">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
		{{# } }}

		{{# } }}
		{{# } }}
	</div>
</script>
<script type="text/html" title="余量/占用量" id="leftUseTpl">
	{{# if(d.mInfo.type=='accessories'){ }}
	<span class="stock-{{ d.mid }}">{{ d.stock_left }}</span> / {{ d.stock_use_num }}
	{{# }else{ }}
	<span class="stock-{{ d.mid }}">{{ d.metre_left }}</span> / {{ d.apply_and_used_0_apply }}
	{{# } }}
</script>
<script type="text/html" title="按钮组" id="subButtonTpl">
	<div style="line-height:35px;">

		{{# if(d.arrive_time==0){ }}
		<a href="javascript:void(0)" onclick="arriveTime({{ d.mid }})" title="到料" data-mid="{{ d.mid }}" data-order_id="{{ d.order_id }}" class="layui-btn layui-btn-sm  arrive-time arrive-time-{{ d.mid }}">到料</a>
		{{# }else{ }}
		<!--            <a href="javascript:void(0)" onclick="arriveTime({{ d.mid }})" title="更新" data-mid="{{ d.mid }}" data-order_id="{{ d.order_id }}" class="layui-btn layui-btn-sm layui-btn-warm arrive-time arrive-time-{{ d.mid }}">更新</a>-->
		{{# } }}
		<a href="javascript:void(0)" title="打标" style="{{# if(d.arrive_time==0){ }}display:none {{# } }}" data-mid="{{ d.mid }}" class="layui-btn layui-btn-sm layui-btn-primary make-tag make-tag-{{ d.mid }}">打标</a>

		{{# if(d.type!='accessories'){ }}
		{{# if(d.caigou_status==0){ }}
		<a href="javascript:void(0)" title="未批色" data-mid={{ d.mid }} data-order_id={{ d.order_id }} class="layui-btn layui-btn-sm layui-btn-warm approval-color approval-color-{{ d.mid }}">未批色</a>
		{{# }else if(d.caigou_status==2){ }}
		<a href="javascript:void(0)" title="批色未通过" data-mid={{ d.mid }} data-order_id={{ d.order_id }} class="layui-btn layui-btn-sm layui-btn-warm approval-color approval-color-{{ d.mid }}">批色未通过</a>
		{{# } }}
		{{# } }}

		{{# if(d.type=='accessories'){ }}
		<a href="{:url('stock/add')}?client_ordernum={{ d.p.client_ordernum }}&material_sku={{ d.material_sku }}&mid={{ d.mid }}&_t=2" class="layui-btn layui-btn-sm hisi-iframe" hisi-data="{width: '500px', height: '500px'}" title="辅料入库">入库</a>
		{{# }else{ }}
		<a href="{:url('materialStock/add')}?client_ordernum={{ d.p.client_ordernum }}&material_sku={{ d.material_sku }}&mid={{ d.mid }}&_t=2" class="layui-btn layui-btn-sm hisi-iframe" hisi-data="{width: '500px', height: '500px'}" title="余料入库">入库</a>
		{{# } }}
		<a href="{:url('returnClothnum')}?mid={{ d.mid }}" title="退料" class="layui-btn layui-btn-sm layui-btn-normal hisi-iframe" hisi-data="{width: '900px', height: '500px'}">退料</a>
		{{# if(d.send_goods_status==0){ }}
		<a href="javascript:void(0)" onclick="send_goods_status(this,{{ d.mid }},{{ d.tiaoshu }})" title="未发货" data-mid="{{ d.mid }}" data-order_id="{{ d.order_id }}" class="layui-btn layui-btn-sm layui-btn-warm send_goods_status-{{ d.mid }}" style="background-color: #c58f03;">未发货</a>
		<a href="javascript:void(0)"  title="已发货" data-mid="{{ d.mid }}" data-order_id="{{ d.order_id }}" class="layui-btn layui-btn-sm layui-btn-disabled send_goods_status-{{ d.mid }}" style="display:none;">已发货</a>
		{{# }else{ }}
		<a href="javascript:void(0)"  title="已发货" data-mid="{{ d.mid }}" data-order_id="{{ d.order_id }}" class="layui-btn layui-btn-sm layui-btn-disabled send_goods_status-{{ d.mid }}">已发货</a>
		{{# } }}
	</div>
</script>

<div id="approvalColorTpl" style="display:none;" class="pt20 pl20">
	<form class="layui-form layui-form-pane" lay-verify="" action="" method="get">
		<div class="layui-form-item">
			<div class="layui-inline">
				<label class="layui-form-label">批色结果</label>
				<div class="layui-input-inline">
					{:Form::radio('status', 1, ['1' => '通过', '2'=>'不通过'], '', '')}
				</div>
			</div>
		</div>
	</form>
</div>

<div id="makeTagTpl" style="display:none;" class="pt20 pl20">
	<form class="layui-form layui-form-pane" lay-verify="" action="" method="get">
		<div class="layui-form-item">
			<div class="layui-inline">
				<label class="layui-form-label">打标条数</label>
				<div class="layui-input-inline">
					<input type="text" name="number" lay-verify="number|required" placeholder="输入条数" class="layui-input">
				</div>
			</div>
			<div class="layui-inline">
				<label class="layui-form-label">备注</label>
				<div class="layui-input-inline">
					<input type="text" name="remark" lay-verify="required" placeholder="输入备注" class="layui-input">
				</div>
			</div>
			<div class="layui-inline">
				<label class="layui-form-label">档口</label>
				<div class="layui-input-inline stall-select">
					{:Form::select('stalls_id','' , $stallsKV, 'stall-ids', 'layui-input','lay-search="" lay-verify="required"')}
				</div>
			</div>
			<div class="layui-inline">
				<label class="layui-form-label">是否库存</label>
				<div class="layui-input-inline">
					{:Form::radio('is_from_stock', '', ['0' => '否', 1=>'是'], '', '')}
				</div>
			</div>
			<div class="layui-inline">
				<label class="layui-form-label">是否共用</label>
				<div class="layui-input-inline">
					{:Form::radio('is_share', '', ['0' => '否', 1=>'是'], '', '')}
				</div>
			</div>
		</div>
	</form>
</div>
<script src="__PUBLIC_JS__/jquery.2.1.4.min.js?v={:config('hisiphp.version')}"></script>
<script src="__PUBLIC_JS__/xm-select/dist/xm-select.js?v={:config('hisiphp.version')}"></script>
<script src="__PUBLIC_JS__/vue@3.2.26/dist/vue.global.js"></script>
<script type="text/javascript">
	var purchasingUserKV = {:json_encode($purchasingUserKV);};
	var orderFrom = {:json_encode($orderFrom);};
	var where=where1="";
	var hreStr=window.location.search;
	var page_info;
	layui.use(['upload', 'opTable', 'jquery', 'tool', 'laydate', 'layer', 'form', 'laytpl'], function() {
		var $ = layui.jquery;
		var laydate = layui.laydate;
		var laytpl = layui.laytpl;
		var layer = layui.layer;
		var form = layui.form;
		var upload = layui.upload;
		form.on('submit(demo1)', function (data) {
			var formData = data.field;
		});
		form.render();
		//导出按钮
		$('.export_btn').click(function () {
			var url="{:url('')}";
			var formData= $('#hisi-table-search-optable').serialize();
			var res_url=url+'?export=1&'+formData+"&page="+page_info.page+"&limit="+page_info.limit;
			window.open(res_url);
		});
		//数据统计弹窗操作start
		if(hreStr.indexOf("searchLabel") != '-1'){
			$(".removeStat").remove();
			where1=window.location.search+"&create_date_range="+cookie_get('create_date_range')
					+"&factory_id="+cookie_get('factory_id')
					+"&sku="+cookie_get('sku')
					+"&caichuang_over_date_range="+cookie_get('caichuang_over_date_range')
					+"&order_status="+cookie_get('order_status')
					+"&over_date_range="+cookie_get('over_date_range')
					+"&is_auto_import="+cookie_get('is_auto_import');
			where=where1+"&client_ordernum="+cookie_get('client_ordernum');
			$("#hisi-table-search-optable").attr("action",where1);
		}else{
			// where="?a=";
		}
		//数据统计弹窗操作over
		laydate.render({
			elem: '#create_date_range'
			,range: '~'
			,theme: 'molv'
			,mark: {'{:$today}':''}
			,change: function(value, date, endDate){
				$('#create_date_range').val(value);
				$('#layui-laydate1').remove();//关闭面板
			}
		});

		var opTable = layui.opTable.render({
			elem : '#dataTable'
			,url : "{:url()}"+where
			,page: true
			,limit: 20
			,limits: [20,50,100,150,200]
			,text: {
				none : '暂无相关数据'
			}
			,toolbar: '#toolbar'
			,defaultToolbar: ['filter', 'exports', 'print']
			,cols : [[
				{field:'pic',title : '图片', templet:'#picTpl',width:110}
				,{field:'client_ordernum',title : '订单号/SKU/时效', templet:'#skuTpl',width:200}
				,{field:'factory_id',title : '工厂/分组', templet:'#factoryTpl',width:150}
				,{field:'order_num',title : '下单 / 裁床 / 车间 / 后整 / 打包 / 出货', templet:'#orderNumTpl',width:240}
				,{field:'order_num',title : '可用库存', templet:'#skuStockTpl',width:120}
				,{field:'order_time',title : '时间进度', templet:'#orderTimeTpl',width:220}
				,{field:'order_user',title : '采购执行人', templet:'#orderUserTpl',width:150}
				,{field:'remark_approval_color',title : '批色备注',edit:'text',style:'border-bottom:2px dotted #5FB878;',width:100}
				,{field:'caigou_remark',title : '采购备注',edit:'text',style:'border-bottom:2px dotted #5FB878;',width:100}
				,{field:'btn',title : '操作',templet:'#buttonTpl',width:120}
			]]

			,onEdit: function(obj,res) {
				var value = obj.value //得到修改后的值
						,data = obj.data //得到所在行所有键值
						,field = obj.field; //得到字段

				// 编辑备注
				$.ajax({
					type: "POST",
					url: "{:url('editUnit')}",
					data: "id="+data.id+"&field="+field+"&value="+value,
					dataType:"json",
					success: function(res){
						if (res.code == 1) {
							layer.msg(res.msg, {icon: 1});
						} else {
							layer.msg(res.msg, {icon: 2,anim: 6});
						}
					}
				});
			}

			//  展开的列配置
			,openTable: function (itemData) {
				return {
					elem: '#child' + itemData.LAY_INDEX
					,id: 'child' + itemData.LAY_INDEX
					,data: layui.tool.setDataToList(itemData, itemData.omList)
					,cellMinWidth: 100
					,limit: 20
					,toolbar: false
					//,defaultToolbar: ['filter', 'exports', 'print']
					,cols: [[
						{field: 'name', title: '材料名称',width:160,templet:function(d){return layui.tool.formatMaterialType(d.type, '', 2) + '<span class="copy-item">' + d.name + '</span> <br>sku：<span class="copy-item">' + d.material_sku+'</span>';}}
						,{field:'model',title : '型号',templet:function(d){return d.model;}}
						,{field:'colornum',title : '色号',width:60,templet:function(d){return d.colornum;}}
						,{field:'color',title : '颜色',width:60,templet:function(d){return d.color;}}
						,{field:'supplier',title : '供应商',width:100,templet:function(d){return "<a href='javascript:void(0);' class='supplier' data-supplier='"+d.supplier+"' data-address='"+d.address+"' data-contact='"+d.contact+"'>"+d.supplier+"</a>";}}
						,{field:'fabric_width',title : '幅宽/克重/米',width:120,templet:function(d){return d.fabric_width+' / '+d.weight+' / '+layui.tool.bcdiv(100000, d.fabric_width*d.weight)+'<br>';}}
						,{field:'jing_material_dosage',title : '净用量',width:60}
						,{field:'total_material_dosage',title : '总用量',width:60}
						,{field:'col1',title : '余料已/未使用',templet:'#subMaterialUseTpl',width:80}
						,{field:'col2',title : '物料状态',templet:'#purchasingStatusTpl',width:140}
						,{field:'col4',title : '还需用量',width:60,templet:'#needNumTpl'}
						,{field:'caigou_unitprice',title : '单价',width:60}
						,{field:'shiji_caigou_count',title : '总条数',width:60,templet:'#shijiCaigouTpl'}
						,{field:'tiaoshu_detail',title : '条数明细',width:80,templet:'#tiaoshuDetailTpl'}
						,{field:'return_length',title : '退料(米)',width:60}
						,{field:'purchasing_unit',title : '单位',width:40,templet:function(d){return d.purchasing_unit;}}
						,{field:'subbtn',title : '操作',templet:'#subButtonTpl',width:335}
					]]
				}
			}
			,openType : 1
			,done: function(res, curr, count){
				page_info=res.page_info;
				opTable.openAll();
				skuCount_set();
				// $(".layui-table-page div .layui-box").append("<span>共&nbsp;"+res.skuCount+"&nbsp;款</span> <span>&nbsp;&nbsp;|&nbsp;&nbsp;</span> &nbsp;<span>共&nbsp;"+res.allQuantity+"&nbsp;件</span>");
				stat_set();
			}
		});
		/**
		 * layui非静态table搜索渲染
		 * @attr data-table table容器ID
		 * @attr hisi-data table基础参数
		 * @attr action 搜索请求地址
		 */
		$(document).on('submit', '#hisiSearchOpTable,#hisi-table-search-optable', function() {
			var that = $(this),
					arr = that.serializeArray(),
					where = new Array(),
					dataTable = that.attr('data-table') ? that.attr('data-table') : 'dataTable',
					options = new Function('return '+ that.attr('hisi-data'))() || {page: {curr:1}};

			for(var i in arr) {
				where[arr[i].name] = arr[i].value;
			}

			options.url = that.attr('action');
			options.where = where;

			opTable.reload(options);
			return false;
		});
		window.callbackAudit = function(obj, res) {
			//console.log(res);
			if (res.code == 1) {
				$("#layui-table-page1 .layui-box").append("<span>共&nbsp;"+res.skuCount+"&nbsp;款</span> <span>&nbsp;&nbsp;|&nbsp;&nbsp;</span> &nbsp;<span>共&nbsp;"+res.allQuantity+"&nbsp;件</span>");

			}
		}

		// 到料
		window.arriveTime = function(mid) {
			$.ajax({
				type: "POST",
				url: "{:url('purchasingV2/arriveTime')}",
				data: "mid="+mid,
				dataType:"json",
				success: function(res){
					if (res.code == 1) {
						// $('.arrive-time-'+mid).html("更新");
						// $('.arrive-time-'+mid).addClass("layui-btn-warm");
						$('.arrive-time-'+mid).remove();
						$('.make-tag-'+mid).attr("style", "display:;");
						layer.msg(res.msg, {icon: 1,anim: 6});
					} else {
						layer.msg(res.msg, {icon: 2,anim: 6});
					}
				}
			});
		}
		// 发货标识
		window.send_goods_status = function(obj,mid,tiaoshu) {
			if(tiaoshu==0){
				layer.confirm('总条数为0，确定发货吗？', {btn: ['确定','取消']}, function(index){
					$.ajax({
						type: "POST",
						url: "{:url('purchasingV2/send_goods')}",
						data: "mid="+mid,
						dataType:"json",
						success: function(res){
							if (res.code == 1) {
								layer.msg(res.msg, {icon: 1,anim: 6});
								$(obj).remove();
								$('.send_goods_status-'+mid+'').show();
							} else {
								layer.msg(res.msg, {icon: 2,anim: 6});
							}
						}
					});
					layer.close(index);
				}, function(index){
					layer.close(index);
				});
				return true;
			}
			$.ajax({
				type: "POST",
				url: "{:url('purchasingV2/send_goods')}",
				data: "mid="+mid,
				dataType:"json",
				success: function(res){
					if (res.code == 1) {
						layer.msg(res.msg, {icon: 1,anim: 6});
						$(obj).remove();
						$('.send_goods_status-'+mid+'').show();
					} else {
						layer.msg(res.msg, {icon: 2,anim: 6});
					}
				}
			});
		}
		// 打标
		$(document).on('click','.make-tag',function(){
			var mid = $(this).attr('data-mid');
			$('.arrive-time-'+mid).remove();
			var layerMakeTag = layer.open({
				type: 1
				,shade: 0
				,offset: '100px'
				,anim: parseInt(Math.random()*(6+1),10)
				,skin:'layui-layer-molv'
				,title:'打标'
				,content: $('#makeTagTpl')
				,area: ['420px', '550px'] //宽高
				,success: function(layero, index){
					$('input[name=number]').focus();
				}
				,btn: ['保存并打印']
				,yes: function(index, layero){
					var number = $('#makeTagTpl form input[name=number]').val();
					if(!(/^\d+$/.test(number))){
						layer.msg('条数输入错误', {icon: 2,anim: 6});
						return;
					}
					data = $('#makeTagTpl form').serialize();
					$.ajax({
						type: "POST",
						url: "{:url('makeTag')}",
						data: data+"&mid="+mid,
						dataType:"json",
						success: function(res){
							if (res.code == 1) {
								layer.msg(res.msg, {icon: 1});
								$('#makeTagTpl form')[0].reset();
								layer.close(layerMakeTag);
								opTable.reload();
								window.open(res.data.url);
							} else {
								layer.msg(res.msg, {icon: 2,anim: 6});
							}
						}
					});
				}
			});
		});
		// 批色
		$(document).on('click','.approval-color',function(){
			var mid = $(this).attr('data-mid');
			var order_id = $(this).attr('data-order_id');
			var layerApprovalColor = layer.open({
				type: 1
				,shade: 0
				,offset: '100px'
				,anim: parseInt(Math.random()*(6+1),10)
				,skin:'layui-layer-molv'
				,title:'批色'
				,content: $('#approvalColorTpl')
				,success: function(layero, index){
				}
				,btn: ['确认']
				,yes: function(index, layero){
					data = $('#approvalColorTpl form').serialize();
					$.ajax({
						type: "POST",
						url: "{:url('approvalColor')}",
						data: data+"&mid="+mid+"&order_id="+order_id,
						dataType:"json",
						success: function(res){
							if (res.code == 1) {
								layer.msg(res.msg, {icon: 1});
								$('#approvalColorTpl form')[0].reset();
								layer.close(layerApprovalColor);

								if(layui.tool.getQueryString(data, 'status') == 2) {
									$(".approval-color-"+mid).attr('title', '批色未通过');
									$(".approval-color-"+mid).html('批色未通过');
									$('.arrive-time-'+mid).remove();
								} else {
									$(".approval-color-"+mid).remove();
									$('.arrive-time-'+mid).remove();
									$('.make-tag-'+mid).attr("style", "display:;");
								}

							} else {
								layer.msg(res.msg, {icon: 2,anim: 6});
							}
						}
					});
				}
			});
		});

		//以下没测试或跟踪过
		//增加新增
		$('.stall-select .layui-anim-upbit').append("<a href='{:url('Stalls/add')}' hisi-data='{}' style='margin-left:55px' class='layui-btn hisi-iframe'>去新增</a>");
		// 入库后更新库存数
		window.updateStock = function(mid, num) {
			//console.log(mid+'-'+num);
			var oriNum = layui.tool.parseFloat($('.stock-'+mid).html());
			$('.stock-'+mid).html(layui.tool.bcadd(num, oriNum));
		}
		// 全部批色后回调
		window.callbackApprovalColor = function(obj, res) {
			if (res.code == 1) {
				obj.remove();
				if (res.data.is_all_over == 1) {
					var orderId = res.data.order_id;
					$('.approval-color-'+orderId).remove();
				}
			}
		}
		// 更新物料状态
		window.updateMaterialStatus = function(mid) {
			$.ajax({
				type: "POST",
				url: "{:url('getMaterialStatus')}",
				data: "mid="+mid,
				dataType:"json",
				success: function(res){
					if (res.code == 1) {
						var Tpl = $('#purchasingStatusTpl').html().replace(/material-status/g, '');
						laytpl(Tpl).render(res.data, function(html){
							$('.material-status-'+mid).html(html);
						});
					} else {
						opTable.reload();
					}
				}
			});
		}
		// 设置采购执行人
		$(document).on('change','.caigou-user',function(){
			var caigouUserId = $(this).val();
			var orderId = $(this).attr('data-key');
			if (caigouUserId > 0) {
				$.ajax({
					type: "POST",
					url: "{:url('setCaigouUser')}",
					data: "caigou_user_id="+caigouUserId+"&order_id="+orderId,
					dataType:"json",
					success: function(res){
						if (res.code == 1) {
							layer.msg(res.msg, {icon: 1});
						} else {
							layer.msg(res.msg, {icon: 2,anim: 6});
						}
					}
				});
			}
		});
		// 辅料开始采购
		$(document).on('click','.start-purchasing',function(){
			var orderId = $(this).attr('data-order_id');
			var materialId = $(this).attr('data-material_id');
			var mid = $(this).attr('data-mid');
			$.ajax({
				type: "POST",
				url: "{:url('distributingFeedV2/startPurchasing')}",
				data: "order_id="+orderId+"&material_id="+materialId,
				dataType:"json",
				success: function(res){
					if (res.code == 1) { // 使用库存完成采购
						layer.msg(res.msg, {icon: 1});
						updateMaterialStatus(mid);
					} else if(res.code == 2) {
						layer.msg(res.msg, {icon: 1,end:function(){
								if(res.data.info != '') layui.tool.copyText(res.data.info);
							}});
						updateMaterialStatus(mid);
					} else {
						layer.msg(res.msg, {icon: 2,anim: 6});
					}
				}
			});
		});
		// 面料开始采购
		$(document).on('click','.start-purchasing-metre',function(){
			var orderFrom = $(this).attr('data-order_from');
			var clientOrdernum = $(this).attr('data-client_ordernum');
			var name = $(this).attr('data-name');
			var colornum = $(this).attr('data-colornum');
			var color = $(this).attr('data-color');
			var num = $(this).attr('data-num');
			var orderId = $(this).attr('data-order_id');
			var materialId = $(this).attr('data-material_id');
			var mid = $(this).attr('data-mid');
			var model = $(this).attr('data-model');
			var sku=$(this).attr('data-sku');
			var weight=$(this).attr('data-weight');
			$.ajax({
				type: "POST",
				url: "{:url('purchasingV2/startPurchasing')}",
				data: "order_id="+orderId+"&material_id="+materialId,
				dataType:"json",
				success: function(res){
					if (res.code == 1) {
						updateMaterialStatus(mid);
					} else {
						layer.msg(res.msg, {icon: 2,anim: 6});
					}
				}
			});

			msg = orderFrom + " \\ " + clientOrdernum + " \\ " + sku + " \\ 克重" + weight + " \\ " + name + " \\ "+colornum+" \\ "+color+" \\ "+num+" \\ "+model;
			layui.tool.copyText(msg);
		});
		// 供应商点击
		$(document).on('click','.supplier',function(){
			var content = $(this).attr('data-supplier') +"<br>"+ $(this).attr('data-contact') +"<br>"+ $(this).attr('data-address')
			layer.tips(content, this);
		});

		function getSearchLabel(){
			$.ajax({
				type: "POST",
				url: "{:url('purchasingV2/index?action=refreshSearchLabels')}",
				data: "action=refreshSearchLabels",
				dataType:"json",
				success: function(res){
					if (res.code == 0) {
						$(".searchLabeltag").html(res.labelstr);
					}
				}
			});
			setTimeout(function(){
				getSearchLabel();
			},10000);
		}
		setTimeout(function(){
			getSearchLabel();
		},10000);//10秒更新一次搜索标签条数信息



		//物料状态选择操作
		form.on('select(material_status_select)', function(data){
			// console.log(data);
			switch (data.value) {
				case '0':
					$('[name="material_property_v2"]').val(0);
					$('#material_property_select').val(0);
					$('#material_property_select').attr("disabled", "disabled");
					break;
				case '1':
				case '2':
				case '3':
				case '4':
				case '13':
				case '14':
					$('#material_property_select').removeAttr("disabled");
					break;
				case '5': //未批色
				case '6':
				case '7':
					$('[name="material_property_v2"]').val(1);
					$('#material_property_select').val(1);
					$('#material_property_select').attr("disabled","disabled");
					break;
				case '8':
				case '9':
					$('[name="material_property_v2"]').val(0);
					$('#material_property_select').val(0);
					$('#material_property_select').attr("disabled","disabled");
					break;
				case '10':
				case '11':
				case '15':
				case '16':
					$('[name="material_property_v2"]').val(0);
					$('#material_property_select').val(0);
					$('#material_property_select').attr("disabled","disabled");
					break;
				case '12':
					$('#material_property_select').val(0);
					$('[name="material_property_v2"]').val(0);
					$('#material_property_select').attr("disabled","disabled");
					break;
			}
			switch (data.value) {
				case '0':
					$('[name="arrive_time_status_v2"]').val(0);
					$('#arrive_time_status_select').val(0);
					$('#arrive_time_status_select').attr("disabled","disabled");
					break;
				case '1':
				case '2':
				case '3':
				case '4':
				case '5': //未批色
				case '6':
				case '7':
				case '13':
				case '14':
					$('[name="arrive_time_status_v2"]').val(0);
					$('#arrive_time_status_select').val(0);
					$('#arrive_time_status_select').removeAttr("disabled");
					break;
				case '8':
				case '9':
					$('[name="arrive_time_status_v2"]').val(0);
					$('#arrive_time_status_select').val(0);
					$('#arrive_time_status_select').attr("disabled","disabled");
					break;
				case '10':
				case '11':
					$('[name="arrive_time_status_v2"]').val(0);
					$('#arrive_time_status_select').val(0);
					$('#arrive_time_status_select').removeAttr("disabled");
					break;
				case '12':
				case '15':
				case '16':
					$('[name="arrive_time_status_v2"]').val(0);
					$('#arrive_time_status_select').val(0);
					$('#arrive_time_status_select').attr("disabled","disabled");
					break;
			}
			form.render('select');  //form.render();这样就是所有
		})
		//物料属性选择操作
		form.on('select(material_property_select)', function(data){
			$('[name="material_property_v2"]').val(data.value);
		});
		//到料状态选择操作
		form.on('select(arrive_time_status_select)', function(data){
			$('[name="arrive_time_status_v2"]').val(data.value);
		});
	});
	function skuCount_set() {
		$.ajax({
			type: "POST",
			url: "{:url('purchasingV2/otherListData')}"+where,
			data: $('#hisi-table-search-optable').serialize(),
			dataType:"json",
			success: function(res){
				if (res.code == 1) {
					$(".layui-table-page div .layui-box").append("<span>共&nbsp;"+res.skuCount+"&nbsp;款</span> <span>&nbsp;&nbsp;|&nbsp;&nbsp;</span> &nbsp;<span>共&nbsp;"+res.allQuantity+"&nbsp;件</span>");
				} else {
					layer.msg(res.msg, {icon: 2,anim: 6});
				}
			}
		});
	}
	//数据统计设置
	function stat_set() {
		$.ajax({
			type: "POST",
			url: "{:url('purchasingV2/purchasing_index',['page'=>1,'a'=>''])}",
			data: $('#hisi-table-search-optable').serialize(),
			dataType:"json",
			success: function(res){
				if (res.stat !== undefined) {
					var p = res.stat;
					var w = res.stat.detailWhere;

					$.cookie("client_ordernum",w.client_ordernum,{ path:"/" });
					$.cookie("create_date_range",w.create_date_range,{ path:"/" });
					$.cookie("factory_id",w.factory_id,{ path:"/" });
					$.cookie("caichuang_over_date_range",w.caichuang_over_date_range,{ path:"/" });
					$.cookie("order_status",w.order_status,{ path:"/" });
					$.cookie("over_date_range",w.over_date_range,{ path:"/" });
					$.cookie("sku",w.sku,{ path:"/" });
					$.cookie("is_auto_import",w.is_auto_import,{ path:"/" });

					$('.ac-item').html(p.allCount);
					$('.stat-fcoc-item').html(p.fabricCgOverCount);
					$('.stat-fcnc-item').html(p.fabricCgNotCount);
					$('.stat-rmc-item').html(p.returnMaterialCount);
					$('.stat-acoc-item').html(p.apColorOverCount);
					$('.stat-acnc-item').html(p.apColorNotCount);
					$('.stat-acnoc-item').html(p.apColorNoCount);
					$('.stat-csoc-item').html(p.ckClothSkOverCount);
					$('.stat-csnc-item').html(p.ckClothSkNotCount);
					$('.stat-coc-item').html(p.caichuangOverCount);
					$('.stat-cnc-item').html(p.caichuangNotCount);
					$('.stat-aoc-item').html(p.acOverCount);
					$('.stat-anc-item').html(p.acNotCount);
					$('.stat-acNoCount-item').html(p.acNoCount);

					$('.stat-fcocp-item').html(p.fabricCgOverCountPer);
					$('.stat-rmcp-item').html(p.returnMaterialCountPer);
					$('.stat-fncp-item').html(p.fabricCgNotCountPer);
					$('.stat-acocp-item').html(p.apColorOverCountPer);
					$('.stat-rmcps-item').html(p.returnMaterialCountPer);
					$('.stat-acncp-item').html(p.apColorNotCountPer);
					$('.stat-acnocp-item').html(p.apColorNoCountPer);
					$('.stat-csocp-item').html(p.ckClothSkOverCountPer);
					$('.stat-csncp-item').html(p.ckClothSkNotCountPer);
					$('.stat-cocp-item').html(p.caichuangOverCountPer);
					$('.stat-cncp-item').html(p.caichuangNotCountPer);
					$('.stat-aocp-item').html(p.acOverCountPer);
					$('.stat-ancp-item').html(p.acNotCountPer);
					$('.stat-acNoCountp-item').html(p.acNoCountPer);
				}
			}
		});
	}

	statistics();
	function statistics() {
		$.ajax({
			type: "POST",
			url: "{:url('statistics')}",
			data: {},
			dataType:"json",
			success: function(res){
				$.each( res.data, function(i, n){
					var i1=1+i*2;
					var i2=2+i*2;
					// console.log(i1);
					var html_day_1='<a href="{:url("statistics_deatail")}?type=order_shixiao&num='+i+'&day=1" class="hisi-iframe"  hisi-data="{width: \'50%\', height: \'50%\'}">'+n.day_1+'</a>';
					var html_day_2='<a href="{:url("statistics_deatail")}?type=order_shixiao&num='+i+'&day=2" class="hisi-iframe"  hisi-data="{width: \'50%\', height: \'50%\'}">'+n.day_2+'</a>';
					var html_day_3='<a href="{:url("statistics_deatail")}?type=order_shixiao&num='+i+'&day=3" class="hisi-iframe"  hisi-data="{width: \'50%\', height: \'50%\'}">'+n.day_3+'</a>';
					var html_day_4='<a href="{:url("statistics_deatail")}?type=order_shixiao&num='+i+'&day=4" class="hisi-iframe"  hisi-data="{width: \'50%\', height: \'50%\'}">'+n.day_4+'</a>';
					var html_day_5='<a href="{:url("statistics_deatail")}?type=order_shixiao&num='+i+'&day=5" class="hisi-iframe"  hisi-data="{width: \'50%\', height: \'50%\'}">'+n.day_5+'</a>';
					var html_day_not='<a href="{:url("statistics_deatail")}?type=order_shixiao&num='+i+'&day=-1" class="hisi-iframe"  hisi-data="{width: \'50%\', height: \'50%\'}">'+n.day_not+'</a>';

					$('#statistics_order_shixiao').find('tr:eq(0) td:eq('+i1+')').html(html_day_1);
					$('#statistics_order_shixiao').find('tr:eq(0) td:eq('+i2+')').html(n.day_1_baifeng+'%');
					$('#statistics_order_shixiao').find('tr:eq(1) td:eq('+i1+')').html(html_day_2);
					$('#statistics_order_shixiao').find('tr:eq(1) td:eq('+i2+')').html(n.day_2_baifeng+'%');
					$('#statistics_order_shixiao').find('tr:eq(2) td:eq('+i1+')').html(html_day_3);
					$('#statistics_order_shixiao').find('tr:eq(2) td:eq('+i2+')').html(n.day_3_baifeng+'%');
					$('#statistics_order_shixiao').find('tr:eq(3) td:eq('+i1+')').html(html_day_4);
					$('#statistics_order_shixiao').find('tr:eq(3) td:eq('+i2+')').html(n.day_4_baifeng+'%');
					$('#statistics_order_shixiao').find('tr:eq(4) td:eq('+i1+')').html(html_day_5);
					$('#statistics_order_shixiao').find('tr:eq(4) td:eq('+i2+')').html(n.day_5_baifeng+'%');
					$('#statistics_order_shixiao').find('tr:eq(5) td:eq('+i1+')').html(html_day_not);
					$('#statistics_order_shixiao').find('tr:eq(5) td:eq('+i2+')').html('');
				});
				// $('#statistics_order_shixiao').find('tr:eq(0) td:eq(1)').html('1');
				// $('#statistics_order_shixiao').find('tr:eq(0) td:eq(2)').html('1%');
				// $('#statistics_order_shixiao').find('tr:eq(1) td:eq(1)').html('2');
				// $('#statistics_order_shixiao').find('tr:eq(1) td:eq(2)').html('2%');
				// $('#statistics_order_shixiao').find('tr:eq(2) td:eq(1)').html('3');
				// $('#statistics_order_shixiao').find('tr:eq(2) td:eq(2)').html('3%');
				// $('#statistics_order_shixiao').find('tr:eq(3) td:eq(1)').html('4');
				// $('#statistics_order_shixiao').find('tr:eq(3) td:eq(2)').html('4%');
				// $('#statistics_order_shixiao').find('tr:eq(4) td:eq(1)').html('5');
				// $('#statistics_order_shixiao').find('tr:eq(4) td:eq(2)').html('5%');
				// $('#statistics_order_shixiao').find('tr:eq(5) td:eq(1)').html('6');
				// $('#statistics_order_shixiao').find('tr:eq(5) td:eq(2)').html('6%');
			}
		});
	}
	statistics_material_shixiao();
	function statistics_material_shixiao() {
		$.ajax({
			type: "POST",
			url: "{:url('statistics',['type'=>'material_shixiao',])}",
			data: {},
			dataType:"json",
			success: function(res){
				$.each( res.data, function(i, n){
					var i1=1+i*2;
					var i2=2+i*2;
					// console.log(i1);
					var html_day_1='<a href="{:url("statistics_deatail")}?type=material_shixiao&num='+i+'&day=1" class="hisi-iframe"  hisi-data="{width: \'50%\', height: \'50%\'}">'+n.day_1+'</a>';
					var html_day_2='<a href="{:url("statistics_deatail")}?type=material_shixiao&num='+i+'&day=2" class="hisi-iframe"  hisi-data="{width: \'50%\', height: \'50%\'}">'+n.day_2+'</a>';
					var html_day_3='<a href="{:url("statistics_deatail")}?type=material_shixiao&num='+i+'&day=3" class="hisi-iframe"  hisi-data="{width: \'50%\', height: \'50%\'}">'+n.day_3+'</a>';
					var html_day_4='<a href="{:url("statistics_deatail")}?type=material_shixiao&num='+i+'&day=4" class="hisi-iframe"  hisi-data="{width: \'50%\', height: \'50%\'}">'+n.day_4+'</a>';
					var html_day_5='<a href="{:url("statistics_deatail")}?type=material_shixiao&num='+i+'&day=5" class="hisi-iframe"  hisi-data="{width: \'50%\', height: \'50%\'}">'+n.day_5+'</a>';
					var html_day_not='<a href="{:url("statistics_deatail")}?type=material_shixiao&num='+i+'&day=-1" class="hisi-iframe"  hisi-data="{width: \'50%\', height: \'50%\'}">'+n.day_not+'</a>';

					$('#statistics_material_shixiao').find('tr:eq(0) td:eq('+i1+')').html(html_day_1);
					$('#statistics_material_shixiao').find('tr:eq(0) td:eq('+i2+')').html(n.day_1_baifeng+'%');
					$('#statistics_material_shixiao').find('tr:eq(1) td:eq('+i1+')').html(html_day_2);
					$('#statistics_material_shixiao').find('tr:eq(1) td:eq('+i2+')').html(n.day_2_baifeng+'%');
					$('#statistics_material_shixiao').find('tr:eq(2) td:eq('+i1+')').html(html_day_3);
					$('#statistics_material_shixiao').find('tr:eq(2) td:eq('+i2+')').html(n.day_3_baifeng+'%');
					$('#statistics_material_shixiao').find('tr:eq(3) td:eq('+i1+')').html(html_day_4);
					$('#statistics_material_shixiao').find('tr:eq(3) td:eq('+i2+')').html(n.day_4_baifeng+'%');
					$('#statistics_material_shixiao').find('tr:eq(4) td:eq('+i1+')').html(html_day_5);
					$('#statistics_material_shixiao').find('tr:eq(4) td:eq('+i2+')').html(n.day_5_baifeng+'%');
					$('#statistics_material_shixiao').find('tr:eq(5) td:eq('+i1+')').html(html_day_not);
					$('#statistics_material_shixiao').find('tr:eq(5) td:eq('+i2+')').html('');
				});
			}
		});
	}

	//浏览器兼容处理--coolie，在以前如不存在，就返回'' 而不是null
	function cookie_get(name='') {
		var temp=$.cookie(name);
		if(temp==null){
			return '';
		}
		return temp;
	}

	//表格头部显示设置
	$(document).ready(function(){   //在文档加载完毕后执行
		$(window).scroll(function(){   //开始监听滚动条
			var topp = $(document).scrollTop();
			if(topp > 34 && document.body.offsetWidth<=1200){
				$('.fixed-bar-tr-header').attr('style','margin-top: 65px;');
			}
		})
	});
</script>